package com.boot.consumer;

import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.nio.charset.StandardCharsets;

/**
 * DESC: Rocket消费者
 *
 * @author WangJie
 * @date Created in 2025-03-04 20:21
 */
//@Component
public class RocketConsumer{

    private static final Logger logger = LoggerFactory.getLogger(RocketConsumer.class);

    //@Service
    @RocketMQMessageListener (topic = "${rocketmq.topic}", consumerGroup = "${rocketmq.consumer.group}")
    public class ConsumerSend implements RocketMQListener<MessageExt> {
        @Override
        public void onMessage(MessageExt message) {
            String body = new String(message.getBody(), StandardCharsets.UTF_8);
            logger.info("Received1 messageId:{}", message.getMsgId());
            logger.info("Received1 message:{}", body);
        }
    }

    //@Service
    @RocketMQMessageListener (topic = "${rocketmq.topic}", consumerGroup = "${rocketmq.consumer.group}")
    public class ConsumerSend2 implements RocketMQListener<MessageExt> {
        @Override
        public void onMessage(MessageExt message) {
            String body = new String(message.getBody(), StandardCharsets.UTF_8);
            logger.info("Received2 messageId:{}", message.getMsgId());
            logger.info("Received2 message:{}", body);

        }
    }
}

